package ru.megazlo.basemvc.controllers.base;

import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collection;
import java.util.Locale;

public class AjaxHttpServletResponse implements HttpServletResponse, AutoCloseable {

	private ServletOutputStream stream = new ServletOutputStream() {
		@Override
		public boolean isReady() {
			return false;
		}

		@Override
		public void setWriteListener(WriteListener writeListener) {

		}

		@Override
		public void write(int b) throws IOException {

		}
	};
	private final StringWriter sw = new StringWriter();
	private final PrintWriter writer = new PrintWriter(sw, true);
	private HttpServletResponse response;

	public AjaxHttpServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	public String getAjaxResult() {
		return sw.getBuffer().toString();
	}

	public void close() {
		writer.close();
	}

	@Override
	public void addCookie(Cookie cookie) {
		response.addCookie(cookie);
	}

	@Override
	public boolean containsHeader(String s) {
		return response.containsHeader(s);
	}

	@Override
	public String encodeURL(String s) {
		return response.encodeURL(s);
	}

	@Override
	public String encodeRedirectURL(String s) {
		return response.encodeRedirectURL(s);
	}

	@Override
	public String encodeUrl(String s) {
		return response.encodeURL(s);
	}

	@Override
	public String encodeRedirectUrl(String s) {
		return response.encodeRedirectURL(s);
	}

	@Override
	public void sendError(int i, String s) throws IOException {

	}

	@Override
	public void sendError(int i) throws IOException {

	}

	@Override
	public void sendRedirect(String s) throws IOException {

	}

	@Override
	public void setDateHeader(String s, long l) {

	}

	@Override
	public void addDateHeader(String s, long l) {

	}

	@Override
	public void setHeader(String s, String s2) {

	}

	@Override
	public void addHeader(String s, String s2) {

	}

	@Override
	public void setIntHeader(String s, int i) {

	}

	@Override
	public void addIntHeader(String s, int i) {

	}

	@Override
	public void setStatus(int i) {

	}

	@Override
	public void setStatus(int i, String s) {

	}

	@Override
	public int getStatus() {
		return 0;
	}

	@Override
	public String getHeader(String s) {
		return null;
	}

	@Override
	public Collection<String> getHeaders(String s) {
		return null;
	}

	@Override
	public Collection<String> getHeaderNames() {
		return null;
	}

	@Override
	public String getCharacterEncoding() {
		return null;
	}

	@Override
	public String getContentType() {
		return null;
	}

	@Override
	public ServletOutputStream getOutputStream() throws IOException {
		return stream;
	}

	@Override
	public PrintWriter getWriter() throws IOException {
		return writer;
	}

	@Override
	public void setCharacterEncoding(String s) {

	}

	@Override
	public void setContentLength(int i) {

	}

	@Override
	public void setContentLengthLong(long l) {

	}

	@Override
	public void setContentType(String s) {

	}

	@Override
	public void setBufferSize(int i) {

	}

	@Override
	public int getBufferSize() {
		return 0;
	}

	@Override
	public void flushBuffer() throws IOException {

	}

	@Override
	public void resetBuffer() {

	}

	@Override
	public boolean isCommitted() {
		return false;
	}

	@Override
	public void reset() {

	}

	@Override
	public void setLocale(Locale locale) {

	}

	@Override
	public Locale getLocale() {
		return null;
	}
}
